package com.ruoyi.community.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.SysCommodity;
import com.ruoyi.community.service.ISysCommodityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品栏Controller
 * 
 * @author zzx
 * @date 2022-06-07
 */
@RestController
@RequestMapping("/commodity/commodity")
public class SysCommodityController extends BaseController
{
    @Autowired
    private ISysCommodityService sysCommodityService;

    /**
     * 查询商品栏列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:commodity:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCommodity sysCommodity)
    {
        startPage();
        List<SysCommodity> list = sysCommodityService.selectSysCommodityList(sysCommodity);
        return getDataTable(list);
    }

    /**
     * 导出商品栏列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:commodity:export')")
    @Log(title = "商品栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCommodity sysCommodity)
    {
        List<SysCommodity> list = sysCommodityService.selectSysCommodityList(sysCommodity);
        ExcelUtil<SysCommodity> util = new ExcelUtil<SysCommodity>(SysCommodity.class);
        util.exportExcel(response, list, "商品栏数据");
    }

    /**
     * 获取商品栏详细信息
     */
    @PreAuthorize("@ss.hasPermi('commodity:commodity:query')")
    @GetMapping(value = "/{commodityId}")
    public AjaxResult getInfo(@PathVariable("commodityId") Long commodityId)
    {
        return AjaxResult.success(sysCommodityService.selectSysCommodityByCommodityId(commodityId));
    }

    /**
     * 新增商品栏
     */
    @PreAuthorize("@ss.hasPermi('commodity:commodity:add')")
    @Log(title = "商品栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCommodity sysCommodity)
    {
        return toAjax(sysCommodityService.insertSysCommodity(sysCommodity));
    }

    /**
     * 修改商品栏
     */
    @PreAuthorize("@ss.hasPermi('commodity:commodity:edit')")
    @Log(title = "商品栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCommodity sysCommodity)
    {
        return toAjax(sysCommodityService.updateSysCommodity(sysCommodity));
    }

    /**
     * 删除商品栏
     */
    @PreAuthorize("@ss.hasPermi('commodity:commodity:remove')")
    @Log(title = "商品栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commodityIds}")
    public AjaxResult remove(@PathVariable Long[] commodityIds)
    {
        return toAjax(sysCommodityService.deleteSysCommodityByCommodityIds(commodityIds));
    }
}
